package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐记录
     * @param categoryId
     * @return
     */
    @Select("select count(*) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Integer categoryId);

    /**
     * 新增套餐
     * @param setmeal
     */
    @AutoFill(OperationType.INSERT)
    @Options(keyProperty = "id",useGeneratedKeys = true)
    @Insert("insert into setmeal(category_id, name, price, status, description, image, create_time, update_time, create_user, update_user) values (#{categoryId},#{name},#{price},#{status},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insert(Setmeal setmeal);

    /**
     * 分页查询
     * @return
     */
    Page<SetmealVO> getAll();

    /**
     * 套餐起售或停售
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Select("select * from setmeal where id = #{id}")
    Setmeal selectById(Long id);

    /**
     * 批量删除套餐
     * @param ids
     * @return
     */
    void delete(List<Long> ids);


    @Update("update setmeal set status = #{status} where id = #{id}")
    void updateStatusByDishId(Integer status,Long id);

    @Select("select *\n" +
            "from setmeal s,setmeal_dish sd,dish d where s.id = sd.setmeal_id and d.id = sd.dish_id")
    List<Setmeal> selectByDishId(Long id);

    @Select("select * from setmeal where category_id = #{categoryId};")
    List<Setmeal> list(Setmeal setmeal);
}
